import { request } from "./request"

/**
 * 将所有公共请求统一放置到此处进行管理，api前缀已配置完成
 */


/**
 * 获取建议列表
 * /api/suggest   get
 */
export const getSuggest = (input) => {
    return request.get(
        // url
        `/suggest`,
        //config,配置的完整列表参见https://www.axios-http.cn/docs/req_config
        {
            params: {
                input
            }
        })
}

/**
 * 查询书籍
 * @param {条件组合} queryCondition
 * @param {当前页} current
 * @param {每页大小} size
 * @returns
 */
export const selectBookList = (queryCondition, current, size) => {
    return request.post(
        // url
        `/bookList/${current}/${size}`,
        queryCondition
    )
}


/**
 * 查询全部分页数据
 * @param {*} input
 * @returns
 */
export const getCatalogAll = () => {
    return request.get(
        // url
        `/catalog`
    )
}

// 登录的方法
export const login = (user) => {
    return request.post(
        // url
        `/login`,
        user
    )
}
const qs = require('qs');
/**
 * content-type:application/x-www-form-urlencoded
 * @param {*} email
 * @returns
 */
// 发送验证码的方法
export const SendRegisterCode = (email) => {
    return request.post(
        // url
        `/SendRegisterCode`,
        qs.stringify({ email })
        ,
    )
}

// 注册
export const register = (users) => {
    return request.post(
        // url
        `/register`,
        users
        ,
    )
}

// 查询用户信息
export const userInquire = (users) => {
    return request.get(
        // url
        `/user/userInquire`,
        users
    )
}


//查询发送文件
export const updateUserInfo = (f, headPortrait) => {
    const FormData = require('form-data');
    const form = new FormData();
    form.append('nickName', f.nickName);
    if (f.code) {
        form.append('code', f.code)
        form.append('email', f.email)
    }
    return request.post(
        // url
        `/user/updateUserInfo`,
        form,
        {
            headers: {
                "Content-Type": "multipart/form-data"
            }
        }
    )
}

/**
 *
 * @returns 发送修改邮箱的密码
 */
export const sendReplaceEmail = (email) => {
    return request.post(
        // url
        `/user/sendReplaceEmail`,
        {
            email
        }
    )
}


/**
 *
 * @returns 查询数据信息
 */
export const getBookInfo = (bookId) => {
    return request.get(
        // url
        `/selectBook/${bookId}`
    )
}

/**
 * 书籍章节信息
 * @param {*} bookId
 * @returns
 */
export const bookChapter = (bookId) => {
    return request.get(
        // url
        `/bookChapter/${bookId}`
    )
}

export const userRelatedInformationOnBook = (bookId) => {
    return request.get(
        // url
        `/user/urInfo/${bookId}`
    )
}
/**
 * 订阅
 * @param {*} bookId
 * @returns
 */
export const addSubscribe = (bookId) => {
    return request.post(
        `/user/subscribe/${bookId}`
    )
}
/**
 * 加入书架
 * @param {*} bookId
 * @returns
 */
export const addBookshelf = (bookId, group) => {
    return request.post(
        `/user/bookRack/${bookId}`,
        {
            group
        }
    )
}
/**
 * 查询用户分组
 * @returns
 */
export const selectGroups = () => {
    return request.get(
        `/user/bookRack/group`
    )
}

/**
 * 更新订阅状态
 * @param {} bookId
 * @returns
 */
export const updateSubscribe = (bookId) => {
    return request.post(
        `user/subscribe/${bookId}`,
    )
}

/**
 *
 * @returns 成为作家
 */
export const becomeAnAuthor = () => {
    return request.post(
        `user/becomeAnAuthor`,
    )
}

/**
 * 查询用户书架
 */
export const selectBookRackList = (group) => {
    if (!group) {
        group = ''
    }
    return request.get(
        '/user/bookRack',
        {
            params: {
                group
            }
        }
    )
}

/**
 * 移动分组
 * @param {*} oldGroup
 * @param {*} targetGroup
 * @param {*} bookIdList
 * @returns
 */
export const moveBookRack = (oldGroup, targetGroup, bookIdList) => {
    return request.post(
        `/user/moveBookRack`,
        bookIdList,
        {
            params: {
                oldGroup,
                targetGroup
            }
        }
    )
}


/**
 * 删除
 * @param {} bookIdList
 * @returns
 */
export const logicalDeletion = (bookIdList) => {
    return request.post(
        `/user/logicalDeletion`,
        bookIdList,
    )
}

//排序书架书籍
export const bookSort = (group, bookIdList) => {
    return request.post(
        `/user/bookSort`,
        bookIdList,
        {
            params: {
                group
            }
        }
    )
}

/**
 * 转换订阅状态
 * @param {} bookId
 * @param {*} bookIdList
 * @returns
 */

export const subscribe = (bookId, bookIdList) => {
    return request.post(
        `/user/subscribe/${bookId}`,
    )
}

/**
 * 获取章节的目录的信息
 */

export const muluxinxi = (bookId) => {
    return request.get(
        `/bookChapter/${bookId}`,

    )

}

/**
 * 获取书籍的的信息
 */

export const shujixinxi = (bookId) => {
    return request.get(
        `/selectBookportion/${bookId}`,

    )

}


/**
 * 获取章节的的信息
 */

export const zhangjiexinxi = (bookId, chapterOrder) => {
    console.log("3333")
    return request.get(
        `/selectChaptergainOrder`,
        {
            params: {
                bookId,
                chapterOrder
            }
        }


    )

}

/**
 * 获取评论的的信息
 */

export const pinglunxinxi = (bookId, chapterOrder) => {
    return request.get(
        `/selectChapterSays/${bookId}/${chapterOrder}`,



    )

}

/**
 * 获取子评论的的信息
 */

export const zipinglunxinxi = (bookId, conversationTargetId) => {
    return request.get(
        `/selectChapterSaysZipin/${bookId}/${conversationTargetId}`,



    )

}

/**
 * 保存评论的的的信息
 */

export const insterChaterSays = (indexs, zhangjieid, textarea) => {
    return request.post(
        `/user/insterChaterSays`,
        { indexs, zhangjieid, textarea }
    )
}

/**
 * 保存子评论的的的信息
 */

export const insterChaterSayszipin = (indexdd, zhangjieid, inputsss) => {
    return request.post(
        `/user/insterChaterSayszipin`,
        { indexdd, zhangjieid, inputsss }
    )
}


/**
 * 点赞和取消点赞
 */

export const giveTheThumbsUp = (actionType, id, oldType) => {
    return request.get(
        `/user/giveTheThumbsUp/${actionType}/${id}`,
        {
            params: {
                oldType
            }
        }


    )

}

/**
 * 获取查询浏览记录
 */

export const selectbrowse = (bookIdss) => {
    return request.get(
        `/user/selectbrowse/${bookIdss}`,
    )

}


/**
 * 保存浏览记录
 */

export const savethebrowse = (chapterId, bookIdss) => {
    return request.get(
        `/user/savethebrowse/${chapterId}/${bookIdss}`,
    )

}




//==================================================TODO:=============================================================================

//作者功能

//获取作品信息
export const worksAll = () => {
    return request.get(
        `/writer/worksAll`,
    )
}
//保存章节
export const saveChapter = (chapterContent) => {
    return request.post(
        `/writer/saveChapter`,
        chapterContent
    )

}

export const deleteChapter = (chapterId) => {
    return request.post(
        `/writer/deleteChapter`,
        {
            chapterId
        }
    )

}


//草稿列表
export const selectDraftList = (bookId) => {
    return request.get(
        `/writer/selectDraftList`,
        {
            params: {
                bookId
            }
        }
    )
}

//发布列表
export const selectPublishList = (bookId) => {
    return request.get(
        `/writer/selectPublishList`,
        {
            params: {
                bookId
            }
        }
    )
}

//获取指定章节的历史
export const getChapterHistory = (chapterId) => {
    return request.get(
        `/writer/getChapterHistory`,
        {
            params: {
                chapterId
            }
        }
    )
}

export const getChapterDeleted = (bookId) => {
    return request.get(
        '/writer/getChapterDeleted',
        {
            params: {
                bookId,
            }
        }
    )
}



//章节内容
export const selectChapter = (bookId, chapterId) => {
    return request.get(
        `/writer/chapter`,
        {
            params: {
                bookId,
                chapterId,
            }
        }
    )
}

//保存为存稿
export const saveAsDraft = (chapterContent) => {
    return request.post(
        `/writer/saveAsDraft`,
        chapterContent
    )
}

//发布
export const releaseRequest = (releaseVo) => {
    return request.post(
        `/writer/release`,
        releaseVo
    )

}

//获取符合文件名的章节内容
export const getChapterContent = (fileName) => {
    return request.get(
        '/writer/getChapterContent',
        {
            params: {
                fileName,
            }
        }
    )
}

//删除列表
export const selectDeleteChapterList = (bookId) => {
    return request.post(
        `/writer/deleteChapter/${bookId}`,
    )
}

//查询书籍
export const selectBook = (bookId) => {
    return request.get(
        `/writer/selectBook/${bookId}`,

    )
}

//修改书籍

export const updateBook = (bookId, book) => {
    const FormData = require('form-data');
    const form = new FormData();
    form.append('bookName', book.bookName);
    form.append('catalogParent', book.catalogParent);
    form.append('catalogName', book.catalogName);
    form.append('synopsis', book.synopsis);
    form.append('promotion', book.promotion);

    return request.post(
        // url
        `/writer/addBook/${bookId}`,
        form,
        {
            headers: {
                "Content-Type": "multipart/form-data"
            }
        }
    )
}

//sale上架书籍
export const sale = (bookId) => {
    return request.get(
        `/writer/sale/${bookId}`,
    )
}

//这在连载的书籍
export const inSerial = () => {
    return request.get(
        `/writer/inSerial`,
    )
}

export const getWriter = () => {
    return request.get(
        `/writer/writerInfo`,
    )
}

export const selectChapterObj = (bookId, chapterId) => {
    return request.get(
        `/selectChapter`,
        {
            params: {
                bookId,
                chapterId
            }
        }
    )
}

export const theBookIsOver = (bookId) => {
    return request.get(
        `/writer/theBookIsOver/${bookId}`,
    )
}



//===================排行========================

export const rankingPaging = (catalog, type, current, size) => {
    if (catalog == "全部分类") {
        catalog = "";
    }
    return request.get(
        `/rankingPaging`,
        {
            params: {
                catalog,
                type,
                current,
                size,
            }
        }
    )
}

export const bookListAll = (catalog) => {
    return request.get(
        `/selectBookList`,
        {
            params: {
                catalog
            }
        }
    )
}

export const catalogOne = () => {
    return request.get(
        `/catalog/one`,
    )
}

export const getBookVoList = (input) => {
    return request.get(
        '/admin/getBookVoList',
        {
            params: {
                input,
            }
        }
    )

}
export const choiceTableData = (bookId) => {
    return request.get(
        '',
        {
            params: {
                bookId,
            }
        }
    )
}

//获取所有key
export const getAllBodyListByKey = () => {
    return request.get(
        '/admin/getAllBodyListByKey',
    )
}

export const getAllType = () => {
    return request.get(
        '/admin/getAllType',
    )
}

// 购买---------------------------------------------------------


//打赏书籍
export const rewardBook = (bookId, amountOfMoney, count) => {
    if (count) {
        return request.post(
            `/order/rewardBook/${bookId}/${amountOfMoney}/${count}`,
        )
    } else {
        return request.post(
            `/order/rewardBook/${bookId}/${amountOfMoney}/1`,
        )
    }

}


//购买章节
export const purchaseSection = (bookId, sort) => {
    return request.post(
        `/order/purchaseSection/${bookId}/${sort}`,
    )
}

//获取当前章节内容，并且查看是否需要购买
export const selectChapterOrder = (bookId, sort) => {
    return request.post(
        `/order/selectChapterOrder/${bookId}/${sort}`,
    )
}


//和读书有关的-----------


export const addUserForAdmin = (userForm) => {
    return request.post(
        `/admin/addUser`,
        userForm
    )
}
export const searchUser = (searchForm) => {
    return request.post(
        '/admin/searchUser',
        searchForm
    )
}
export const deleteUser = (email) => {
    return request.post(
        '/admin/deleteUser',
        {
            email: email
        }
    )
}
export const recoveryUser = (email) => {
    return request.post(
        '/admin/recoveryUser',
        {
            email: email
        }
    )
}
export const getDownholeCount = (intervalSize) => {
    return request.post(
        '/admin/getDownholeCount',
        {
            intervalSize: intervalSize
        }
    )
}
export const deleteDownholeCount = (deleteSize) => {
    return request.post(
        '/admin/deleteDownholeCount',
        {
            deleteSize: deleteSize
        }
    )
}

//广告推荐
export const getAllRecommendByType = (type) => {
    return request.get(
        '/admin/getTypeTheRecommend',
        {
            params: {
                type
            }
        }
    )
}

/**
 * 删除key
 * @param {} key 
 * @returns 
 */
export const delKey = (key) => {
    return request.get(
        '/admin/del',
        {
            params: {
                key
            }
        }
    )
}

// name: "", //推荐标题名
// type: "", //推荐的类型（小说 网页游戏）
// region: "站外", //推荐类型 站外/站内
// body: "", //推荐的内容（站内：书籍id 站外：外站的地址）
// copywriting: "", //推广文案
export const adminGg = (data) => {
    const FormData = require('form-data');
    const form = new FormData();
    form.append('name', data.name);
    form.append('type', data.type);
    form.append('region', data.region);
    form.append('synopsis', data.synopsis);
    form.append('body', data.body);
    form.append('copywriting', data.copywriting);
    return request.post(
        // url
        `/admin/img`,
        form,
        {
            headers: {
                "Content-Type": "multipart/form-data"
            }
        }
    )
}

export const getUserForType = (type) => {
    return request.post(
        '/admin/getUserForType',
        {
            type: type
        }
    )
}
export const getInitializationData = () => {
    return request.post(
        '/admin/getInitializationData',
    )
}




